package com.rst.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.ExamGradingLevels;

@Repository
@Transactional
public class ExamGradingLevelDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void saveExamGradingLevels(ExamGradingLevels examGradingLevels) {
		sessionFactory.getCurrentSession().save(examGradingLevels);	
		
	}

	public ExamGradingLevels getExamGradingLevelsById(Long examGradingLevelsId) {
	    Session session = sessionFactory.getCurrentSession();
	    ExamGradingLevels examGradingLevels = (ExamGradingLevels)session.get(ExamGradingLevels.class, examGradingLevelsId);
		return examGradingLevels;
	}

	@SuppressWarnings("unchecked")
	public List<ExamGradingLevels> getExamGradingLevelsList() {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM ExamGradingLevels el WHERE el.status = :status  ";
	    	
	    Query query = session.createQuery(str);
	    query.setParameter("status",  ExamGradingLevels.ACTIVE);
		return query.list();
	}

	public void updateExamGradingLevels(ExamGradingLevels examGradingLevels) {
		sessionFactory.getCurrentSession().update(examGradingLevels);		
	}	
}




